<style lang="less" scoped>
.permission-list{
    padding: 20px;
    border:1px solid #3F95FF;
    max-height: 200px;
    overflow: auto;
}
</style>
<template>
	<div class="comp-new">
		<el-form ref="newForm" :model="newForm" :label-width="150+'px'">
			<el-form-item label="系统类型：" prop="deviceClassify" :rules="[{ required: true, message: '请选择系统类型' }]">
		    	<el-select v-model="newForm.deviceClassify" multiple placeholder="请选择">
					<el-option :label="item.name" :value="item.id" v-for="(item, index) in sysytmeList" :key="index"></el-option>
				</el-select>
		  	</el-form-item>
			<el-form-item label="通讯方式：" prop="state" :rules="[{ required: true, message: '请选择通讯方式' }]">
		    	<el-checkbox-group v-model="newForm.state">
                    <el-checkbox label="1">短信</el-checkbox>
                    <el-checkbox label="2">语音</el-checkbox>
                </el-checkbox-group>
		  	</el-form-item>
			<el-form-item label="状态：" prop="type" :rules="[{ required: true, message: '请选择状态' }]">
		    	<el-radio-group v-model="newForm.type">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="2">关闭</el-radio>
                </el-radio-group>
		  	</el-form-item>
		</el-form>
	</div>	
</template>
<script>
import { mapState } from 'vuex'
export default {
	name: 'newRecordAccount',
	props: {
		activeData: {
			type: Object,
			default(){
				return null
			},
		}
	},
	computed: {
		...mapState([
			'scale'
		]),
	},
	watch: {
		activeData () {
			this.initForm()
		}
	},
	data () {
		return {
			newForm: {},
            checkedType: [],
			loading: false,
            sysytmeList:[],
		}
	},
	created () {
        this.getSystemList()
		this.initForm()
	},
	methods: {
        getSystemList () {
            this.$get('/fireFightingIOT/historicalAlarmInfo/dictList',{groupname:'系统类型'}).then(res=>{
                this.sysytmeList = res.data
            })
        },
        setType (data) {
            let type = ''
            if(data.length==0){
                type = ''
            }else if(data.length==1){
                type = data[0]
            }else{
                type = 3
            }
            return type
        },
		initForm () {
			this.newForm = {
                businessId:this.activeData.id,
                deviceClassify: '',
                state:[],
                type:''
            }
		},
		submitAction () {
			this.$refs['newForm'].validate((valid) => {
				if (valid) {
					this.$emit('submitting')
					let params = Object.assign({},this.newForm)
                    params.state = this.setType(params.state) //通知类型
					this.$post('/fireFightingIOT/itemSetup/oneClickOnOrOff', params).then( data => {
						this.loading = false
						this.$message.success('保存成功')
						this.$emit('success',data);
					}, error => {
						this.$emit('fail')
						this.$message.error(error.msg);
					})
				} else {
					return false;
				}
			});
		},
		cancelAction () {
			this.$emit('cancel');
		}
	},
}
</script>